/*
 * @Author: silence
 * @Date: 2023-08-18 10:03:29
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-10-18 08:51:47
 * @Description: 配网第一步：检查设备状态，是否符合配网条件
 */
import 'package:ems_neutral_app/base/SilScaffold.dart';
import 'package:ems_neutral_app/common/widgets/cubitWidget/SubmitBtn.dart';
import 'package:ems_neutral_app/pages/Mine/Language/SilLocalizations/SilLocalizations.dart';
import 'package:ems_neutral_app/utils/color/ColorUtils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../utils/router/ARouter.dart';
import 'Controller/DeviceNetworkingController.dart';
import 'DNSetLocalWifiPage.dart';

class DNCheckDevicePage extends StatefulWidget {
  const DNCheckDevicePage({super.key});

  @override
  State<DNCheckDevicePage> createState() => _DNCheckDevicePageState();

  static Route route() {
    return MaterialPageRoute<void>(
      builder: (_) => DNCheckDevicePage(),
      settings: RouteSettings(name: '/DNCheckDevicePage'),
    );
  }
}

class _DNCheckDevicePageState extends State<DNCheckDevicePage> {
  DeviceNetworkingController _controller =
      Get.put(DeviceNetworkingController());

  @override
  Widget build(BuildContext context) {
    return SilScaffold(
      title: LangOf(context)?.deviceNetworking?.checkDevice, //检查设备
      body: mainWidget(),
    );
  }

  mainWidget() {
    return Column(
      children: [
        Expanded(child: contentView()),
        bottomBtn(),
      ],
    );
  }

  /// 内容
  contentView() {
    return ListView(children: [
      Padding(padding: EdgeInsets.only(top: 20.w)),

      /// 提示文字
      SilText(
        LangOf(context)
            ?.deviceNetworking
            ?.checkDevicePrompt, //1.检查储能设备是否开机，确保设备正常运行。\n2.查看数采器是否正常工作。\n3.查看当前手机连接的Wi-Fi网络，是否是2.4GHz网络，如果不是，请查看手机Wi-Fi列表，切换到2.4GHz网络。
        color: ColorUtils.color_font_main,
        fontSize: 14.sp,
        maxLines: 0,
        lineHeight: 1.5.w,
      ),

      /// 图片
      Container(
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 65.w),
        child: SilImage(
          'imgs/device_net/device_net_device_flag.png',
          margin: EdgeInsets.only(top: 30.w),
        ),
      )
    ]);
  }

  /// 底部按钮
  bottomBtn() {
    return SubmitBtn(
      margin: EdgeInsets.only(
          top: 10.w, bottom: MediaQuery.of(context).padding.bottom + 10.w),
      title: LangOf(context)?.deviceNetworking?.nextStep, //'下一步'
      onTapFunc: () async {
        // wifi开关打开，并且有定位权限
        bool isLocationEnabled =
            await _controller.checkWifiSwitchAndLocalPower(context);
        if (isLocationEnabled) {
          ARoute.gotoPage(context, DNSetLocalWifiPage());
        }
      },
    );
  }
}
